// components/msg/chat/chat.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: "",
    chatList: [],
    filterChatList:[],
    filterChatListb:[],
    flag:false,
    valueInput:''
  },
  inputText(e){
    let value = e.detail.value
    this.setData({
     valueInput:value
    })
    if(value !== ''){
      this.setData({
       flag:true
      })
    }else{
     this.setData({
       flag:false
      })
    }
 },

 sendInput(){
   let valueIpt = this.data.valueInput
   wx.request({
     url: 'http://localhost:7001/api/getaddxjydetails',
     method:"POST",
     data:{
      imgurl: 'http://127.0.0.1:7001/public/XJYpng/myimage.jpg',
       message:valueIpt,
       types:0,
       ids:'b',
   filterChatList: [],
   filterChatListb: [],
   flag: false,
   valueInput: '',
   scrollTop:0
     }
     })
 },
 inputText(e) {
   let value = e.detail.value
   this.setData({
     valueInput: value
   })
   if (value !== '') {
     this.setData({
       flag: true
     })
   } else {
     this.setData({
       flag: false
     })
   }
 },
 autoScroll() {
   var that = this
   let query = wx.createSelectorQuery()
   query.select('.message-box-list').boundingClientRect(res => {
     console.log(res);
       that.setData({
           scrollTop: res.height  *200
       })
   })
   query.exec(res => {})
},
 sendInput() {
   let valueIpt = this.data.valueInput
   wx.request({
     url: 'http://localhost:7001/api/getaddxjydetails',
     method: "POST",
     data: {
       imgurl: 'http://127.0.0.1:7001/public/XJYpng/myimage.jpg',
       message: valueIpt,
       types: 0,
       ids: 'b',
     },
     success:(res=>{
     })
   })
   this.autoScroll()
   this.onLoad()
 },
 /**
  * 生命周期函数--监听页面加载
  */
 getChatRecord(){
   wx.request({
     url: 'http://localhost:7001/api/getxjydetails',
     success: (res => {
       console.log(res.data.data)
       this.setData({
         chatList: res.data.data
       })
     })
   })
 },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let ids = options
    wx.request({
      url: 'http://localhost:7001/api/getxjydetails',
      success: (res => {
        this.setData({
          chatList: res.data.data
        })
      })
    })
    wx.request({
      url: 'http://localhost:7001/api/getxjynews',
      success:(res=>{
        res.data.data.filter((item)=>{
           if(ids == item.id){
            wx.setNavigationBarTitle({
              title: item.userName
            })
          }
      })
    this.getChatRecord()
  }),
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})